use std::path::Path;
use libloading::{Library, Symbol};
use serde_json::Value;

// Don't forget to change the path below
const DLL_PATH: &str = r"HWHash.dll";
// const CLASS_NAME: &str = "HWHash";
const METHOD_LAUNCH: &str = "Launch";
const METHOD_JSON_STRING_MINI: &str = "GetJsonStringMini";

fn main() -> Result<(), Box<dyn std::error::Error>> {
    unsafe {
        let lib = Library::new(Path::new(DLL_PATH))?;

        let launch: Symbol<unsafe extern "C" fn() -> ()> = lib.get(METHOD_LAUNCH.as_bytes())?;
        launch();

        let get_json_string_mini: Symbol<unsafe extern "C" fn(bool) -> *const i8> = 
            lib.get(METHOD_JSON_STRING_MINI.as_bytes())?;

        let result_ptr = get_json_string_mini(true);
        let result = std::ffi::CStr::from_ptr(result_ptr).to_string_lossy().into_owned();

        println!("{}", result);

        // Parse and pretty-print JSON (optional)
        let json: Value = serde_json::from_str(&result)?;
        println!("{}", serde_json::to_string_pretty(&json)?);
    }

    Ok(())
}